/*
 * author zby
 * 首页初始化数据
 */

(function (document, window, $, Utils) {
    'use strict';
    $(function () {
        var fns = {};
        window.fns = fns;
        init();
    });

    //入口方法
    function init() {
        var vm = new Vue({
            el: '#itemContent',
            data: {
                memberCounts: 0,
                onlineMembers: 0,
                downloads: 0,
                successDownloads: 0,
                //浏览网站次数
                browseCounts: 0,
                resumeCounts: 0,
                //浏览文章总次数
                acmCount: 0,
                //    浏览网站的各个操作系统
                countOs: {},
                //    按月统计浏览器类型，比如移动端 pc端
                countBtbm: ""
            },
            computed: {
                //注册人数/浏览人数
                mbRate: function () {
                    const rate = parseFloat(this.memberCounts / this.browseCounts * 100).toFixed(2);
                    return "<h5>注册总人数</h5>\n" +
                        " <h2>\n" +
                        "     <span>" + this.memberCounts + "人</span>\n" +
                        "     <span class='tuition-fees'>注册人数/浏览人数</span>\n" +
                        " </h2>\n" +
                        " <span class='text-success'>" + rate + " %</span>\n" +
                        " <div class='progress m-b-0'>\n" +
                        "     <div class='progress-bar progress-bar-info wow fadeInLeft' role='progressbar'\n" +
                        "          aria-valuemin='0' aria-valuemax='100' style='width:" + rate + "%;' data-wow-duration='1.5s' data-wow-delay='1s'><span class='sr-only'>" + rate + "% Complete</span>\n" +
                        "     </div>\n" +
                        " </div>";
                },
                //在线人数/注册人数
                orRate: function () {
                    const rate = parseFloat(this.onlineMembers / this.memberCounts * 100).toFixed(2);
                    return "<h5>在线人数</h5>\n" +
                        " <h2>\n" +
                        "     <span>" + this.onlineMembers + "人</span>\n" +
                        "     <span class='tuition-fees'>在线人数/注册人数</span>\n" +
                        " </h2>\n" +
                        " <span class='text-success'>" + rate + " %</span>\n" +
                        " <div class='progress m-b-0'>\n" +
                        "     <div class='progress-bar progress-bar-info wow fadeInLeft' role='progressbar'\n" +
                        "          aria-valuemin='0' aria-valuemax='100' style='width:" + rate + "%;' data-wow-duration='1.5s' data-wow-delay='1s'><span class='sr-only'>" + rate + "% Complete</span>\n" +
                        "     </div>\n" +
                        " </div>";
                },
                //    下载次数/注册人数
                dmRate: function () {
                    const rate = parseFloat(this.downloads / this.memberCounts * 100).toFixed(2);
                    return "<h5>下载次数</h5>\n" +
                        " <h2>\n" +
                        "     <span>" + this.downloads + "次</span>\n" +
                        "     <span class='tuition-fees'>下载次数/注册人数</span>\n" +
                        " </h2>\n" +
                        " <span class='text-success'>" + rate + " %</span>\n" +
                        " <div class='progress m-b-0'>\n" +
                        "     <div class='progress-bar progress-bar-info wow fadeInLeft' role='progressbar'\n" +
                        "          aria-valuemin='0' aria-valuemax='100' style='width:" + rate + "%;' data-wow-duration='1.5s' data-wow-delay='1s'><span class='sr-only'>" + rate + "% Complete</span>\n" +
                        "     </div>\n" +
                        " </div>";
                },
                //    成功次数/下载次数
                smRate: function () {
                    const rate = parseFloat(this.successDownloads / this.downloads * 100).toFixed(2);
                    return "<h5>下载成功次数</h5>\n" +
                        " <h2>\n" +
                        "     <span>" + this.successDownloads + "次</span>\n" +
                        "     <span class='tuition-fees'>成功次数/下载次数</span>\n" +
                        " </h2>\n" +
                        " <span class='text-success'>" + rate + " %</span>\n" +
                        " <div class='progress m-b-0'>\n" +
                        "     <div class='progress-bar progress-bar-info wow fadeInLeft' role='progressbar'\n" +
                        "          aria-valuemin='0' aria-valuemax='100' style='width:" + rate + "%;' data-wow-duration='1.5s' data-wow-delay='1s'><span class='sr-only'>" + rate + "% Complete</span>\n" +
                        "     </div>\n" +
                        " </div>";
                },
            }
        })
        Utils.getSimpleJson({
            url: "/core/member/counts",
            fn: function (data) {
                vm.memberCounts = data.counts;
            }
        })
        Utils.getSimpleJson({
            url: "/core/member/counts",
            params: {
                online: 'BOOLEAN_YES'
            },
            fn: function (data) {
                vm.onlineMembers = data.counts;
            }
        })
        Utils.getSimpleJson({
            url: "/core/systemRecord/counts",
            fn: function (data) {
                vm.browseCounts = data.counts;
            }
        })
        Utils.getSimpleJson({
            url: "/core/uploadDownloadRecord/counts",
            fn: function (data) {
                vm.downloads = data.counts;
            }
        })
        Utils.getSimpleJson({
            url: "/core/uploadDownloadRecord/counts",
            params: {
                resultType: 'RESULT_TYPE_SUCCESS'
            },
            fn: function (data) {
                vm.successDownloads = data.counts;
            }
        })
        //    简历总人数
        Utils.getSimpleJson({
            url: "/manager/resume/counts",
            fn: function (data) {
                vm.resumeCounts = data.counts;
            }
        })
        //    浏览文章总次数
        Utils.getSimpleJson({
            url: "/manager/browserArticle/counts",
            fn: function (data) {
                vm.acmCount = data.counts;
            }
        })
        //    浏览网站的各个操作系统分析
        Utils.getSimpleJson({
            url: "/core/systemRecord/countOs",
            fn: function (data) {
                vm.countOs = data;
            }
        })
        //    按月统计浏览器类型，比如移动端 pc端
        Utils.getSimpleJson({
            url: "/core/systemRecord/countBtbm",
            fn: function (data) {
                Morris.Area({
                    element: 'extra-area-chart',
                    data: data,
                    xkey: 'period',
                    ykeys: ['mobile', 'pc', 'unknown'],
                    labels: ['mobile', 'pc', 'unknown'],
                    pointSize: 3,
                    fillOpacity: 0,
                    parseTime: false,
                    pointStrokeColors: ['#006DF0', '#65b12d', '#933EC5'],
                    behaveLikeLine: true,
                    gridLineColor: '#e0e0e0',
                    lineWidth: 1,
                    hideHover: 'auto',
                    lineColors: ['#006DF0', '#65b12d', '#933EC5'],
                    resize: true

                });
                vm.countBtbm = data;
            }
        })

    }


})(document, window, jQuery, Utils);